package com.example.tms.controller;

import com.example.tms.bean.*;
import com.example.tms.mapper.*;
import com.example.tms.tools.GlobalParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.web.bind.annotation.*;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.example.tms.annotation.*;

/**
 * App司机注册信息
 */
@RestController
public class DriverAController {

    private final DriverAMapper driverAMapper;
    private final FileMapper fileMapper;
    private final UserMapper userMapper;
    private final DriverMapper diverMapper;
    private final DriverVMapper driverVMapper;


    @Autowired
    public DriverAController(DriverAMapper driverAMapper, FileMapper fileMapper, UserMapper userMapper, DriverMapper diverMapper, DriverVMapper driverVMapper){
        this.driverAMapper = driverAMapper;
        this.fileMapper = fileMapper;
        this.userMapper = userMapper;
        this.diverMapper = diverMapper;
        this.driverVMapper = driverVMapper;
    }

    private final Logger logger = LoggerFactory.getLogger(this.getClass());



    //查询司机注册列表
    @RequestMapping(value = "driverapp", method = RequestMethod.GET)
    public ReturnInfo getDriverApp(@RequestParam(value = "pageNum", defaultValue = "1") String pageNum,
                                     @RequestParam(value = "pageSize", defaultValue = "0") String pageSize,
                                     @RequestParam(required = false, defaultValue = "") String sfzh,
                                     @RequestParam(required = false, defaultValue = "") String xingming,
                                     @RequestParam(required = false, defaultValue = "") String shzt){
        //规格定义
        Specification<DriverApp> specification = new Specification<DriverApp>() {
            /**
             * 构造断言
             * @param root 实体对象引用
             * @param query 规则查询对象
             * @param cb 规则构建对象
             * @return 断言
             */
            @Override
            public Predicate toPredicate(Root<DriverApp> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                List<Predicate> predicates = new ArrayList<>(); //所有的断言
                if (!xingming.equals("")) {
                    predicates.add(cb.like(root.get("xingming").as(String.class), "%" + xingming + "%"));
                }
                if (!sfzh.equals("")) {
                    predicates.add(cb.like(root.get("sfzh").as(String.class), "%" + sfzh + "%"));
                }
                if (!shzt.equals("")) {
                    predicates.add(cb.like(root.get("shzt").as(String.class), "%" + shzt + "%"));
                }
                predicates.add(cb.equal(root.get("sfcz").as(Boolean.class),true));
                Predicate[] p = new Predicate[predicates.size()];
                Predicate predicate = cb.and(predicates.toArray(p));
                query.where(predicate);
                query.orderBy(cb.desc(root.get("lasttime")));
                return query.getRestriction();
            }
        };
        //分页信息
        Pageable pageable = new PageRequest(Integer.valueOf(pageNum)-1,Integer.valueOf(pageSize)); //页码：前端从1开始，jpa从0开始，做个转换
        Page<DriverApp> result= driverAMapper.findAll(specification,pageable); //查询
        List<DriverApp> DriverApps = result.getContent();//获取Content
        String total =String.valueOf(result.getTotalElements());
        return ReturnInfo.info5(total,DriverApps,0,"");
    }

    @RequestMapping(value = "driverapplist", method = RequestMethod.GET)
    public ReturnInfo  getdiverappList(@RequestParam(required = false, defaultValue = "") String sfzh,
                    @RequestParam(required = false, defaultValue = "") String xingming,
                    @RequestParam(required = false, defaultValue = "") String shzt) {
                List<DriverApp> result = driverAMapper.findAll((Root<DriverApp> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) -> {
                    List<Predicate> list = new ArrayList<>();
                    if (!xingming.equals("")) {
                        list.add(criteriaBuilder.like(root.get("xingming").as(String.class), "%" + xingming + "%"));
                    }
                    if (!sfzh.equals("")) {
                        list.add(criteriaBuilder.like(root.get("sfzh").as(String.class), "%" + sfzh + "%"));
                    }
                    if (!shzt.equals("")) {
                        list.add(criteriaBuilder.like(root.get("shzt").as(String.class), "%" + shzt + "%"));
                    }
            list.add(criteriaBuilder.equal(root.get("sfcz").as(Boolean.class), true));
            Predicate[] p = new Predicate[list.size()];
            criteriaQuery.where(criteriaBuilder.and(list.toArray(p)));
            criteriaQuery.orderBy(criteriaBuilder.desc(root.get("lasttime")));
            return criteriaQuery.getRestriction();
        });
        return ReturnInfo.info2(result);
    }

    //查询注册用户信息
    @RequestMapping(value = "diverapp/{sjid}",method = RequestMethod.GET)
    public DriverApp getCarMgmtInfo(@PathVariable("sjid") String sjid){
        return driverAMapper.findBySjidAndSfcz(sjid,true);
    }

    //司机注册
    @MonitorRequest
    @RequestMapping(value = "driverapp", method = RequestMethod.POST)
    public List<Map<String,Object>> createDriverApp(@RequestBody DriverApp driverApp) throws NoSuchAlgorithmException {
        List<Map<String,Object>>  list = new ArrayList<>();
        Map<String,Object>  map = new HashMap<>();

        if(driverApp.getSfzh().equals("")||!checkSfzh(driverApp.getSfzh())){
            map.put("sfzh", "0");
        }else if(driverAMapper.findBySfzhandShzt(driverApp.getSfzh(),"未审核")!=null||driverAMapper.findBySfzhandShzt(driverApp.getSfzh(),"审核通过")!=null||driverAMapper.findBySfzhandShztandSfgezx(driverApp.getSfzh(),"审核不通过")!=null||userMapper.findByYhm(driverApp.getSfzh())!=null){
            map.put("sfzh", "2");
        }
        if(driverApp.getXingming().equals("")||!checkXm(driverApp.getXingming())){
            map.put("xingming", "0");
        }
        if(driverApp.getJiguan().equals("")){
            map.put("jiguan", "0");
        }
        if(driverApp.getJsznjrq().equals("")||!checkRiqi(driverApp.getJsznjrq())){
            map.put("jsznjrq", "0");
        }
        if(driverApp.getCyzgznjrq().equals("")||!checkRiqi(driverApp.getCyzgznjrq())){
            map.put("cyzgznjrq", "0");
        }
        if(driverApp.getMima().equals("")||!checkPsw(driverApp.getMima())){
            map.put("mima", "0");
        }
        if(driverApp.getSjhm().equals("")||!checkSjh(driverApp.getSjhm())){
            map.put("sjhm", "0");
        }else if (driverAMapper.findBySjhmandShzt(driverApp.getSjhm(),"未审核")!=null||driverAMapper.findBySjhmandShzt(driverApp.getSjhm(),"审核通过")!=null||driverAMapper.findBySjhmandShztandSfgezx(driverApp.getSjhm(),"审核不通过")!=null||diverMapper.findByJsysjAndSfcz(driverApp.getSjhm(),true).size()>0){
            map.put("sjhm", "2");
        }
        if(driverApp.getSfzzm().equals("")||driverApp.getSfzzm()==null){
            map.put("sfzzm", "0");
        }
        if(driverApp.getSfzfm().equals("")||driverApp.getSfzfm()==null){
            map.put("sfzfm", "0");
        }
        if(driverApp.getSjsfzsbsz().equals("")||driverApp.getSjsfzsbsz()==null){
            map.put("sjsfzsbsz", "0");
        }
        if(driverApp.getJszzb().equals("")||driverApp.getJszzb()==null){
            map.put("jszzb", "0");
        }
        if(driverApp.getJszfb().equals("")||driverApp.getJszfb()==null){
            map.put("jszfb", "0");
        }
        if(driverApp.getCyzgz1().equals("")||driverApp.getCyzgz1()==null){
            map.put("cyzgz1", "0");
        }
        list.add(map);
        if(map.isEmpty()){
            if (driverApp.getCun()!=null) {
                driverApp.setCun( driverApp.getCun());
            }
            driverApp.setJiguan(driverApp.getJiguan());
            String sfzh = driverApp.getSfzh();
            driverApp.setSfzh(sfzh.toUpperCase());
            String jsznjrq = driverApp.getJsznjrq();
            String jsznjrq1 = jsznjrq.substring(0,10);
            driverApp.setJsznjrq(jsznjrq1);
            String cyzgznjrq = driverApp.getCyzgznjrq();
            String cyzgznjrq1 = cyzgznjrq.substring(0,10);
            driverApp.setCyzgznjrq(cyzgznjrq1);
            driverApp.setSfcz(true);
            driverApp.setLasttime(GlobalParam.getTime());
            driverApp.setXinxi("");
            driverApp.setSfcg(false);
            driverApp.setShzt("未审核");
            driverApp.setSfgrzx(false);
            FileInfo fileInfo1 = fileMapper.findByFileurl(driverApp.getSfzzm());
            fileInfo1.setSfcz(true);
            fileMapper.saveAndFlush(fileInfo1);
            driverApp.setSfzzm(fileInfo1.getFileid());
            FileInfo fileInfo2 = fileMapper.findByFileurl(driverApp.getSfzfm());
            fileInfo2.setSfcz(true);
            fileMapper.saveAndFlush(fileInfo2);
            driverApp.setSfzfm(fileInfo2.getFileid());
            FileInfo fileInfo3 = fileMapper.findByFileurl(driverApp.getSjsfzsbsz());
            fileInfo3.setSfcz(true);
            fileMapper.saveAndFlush(fileInfo3);
            driverApp.setSjsfzsbsz(fileInfo3.getFileid());
            FileInfo fileInfo4 = fileMapper.findByFileurl(driverApp.getJszzb());
            fileInfo4.setSfcz(true);
            fileMapper.saveAndFlush(fileInfo4);
            driverApp.setJszzb(fileInfo4.getFileid());
            FileInfo fileInfo5 = fileMapper.findByFileurl(driverApp.getJszfb());
            fileInfo5.setSfcz(true);
            fileMapper.saveAndFlush(fileInfo5);
            driverApp.setJszfb(fileInfo5.getFileid());
            FileInfo fileInfo6 = fileMapper.findByFileurl(driverApp.getCyzgz1());
            fileInfo6.setSfcz(true);
            fileMapper.saveAndFlush(fileInfo6);
            driverApp.setCyzgz1(fileInfo6.getFileid());
            if(driverApp.getCyzgz2()!=null&&!driverApp.getCyzgz2().equals("")) {
                FileInfo fileInfo7 = fileMapper.findByFileurl(driverApp.getCyzgz2());
                fileInfo7.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo7);
                driverApp.setCyzgz2(fileInfo7.getFileid());
            }
            if(driverApp.getCyzgz3()!=null&&!driverApp.getCyzgz3().equals("")) {
                FileInfo fileInfo8 = fileMapper.findByFileurl(driverApp.getCyzgz3());
                fileInfo8.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo8);
                driverApp.setCyzgz3(fileInfo8.getFileid());
            }
            if(driverApp.getCyzgz4()!=null&&!driverApp.getCyzgz4().equals("")) {
                FileInfo fileInfo9 = fileMapper.findByFileurl(driverApp.getCyzgz4());
                fileInfo9.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo9);
                driverApp.setCyzgz4(fileInfo9.getFileid());
            }
            if(driverApp.getCyzgz5()!=null&&!driverApp.getCyzgz5().equals("")) {
                FileInfo fileInfo10 = fileMapper.findByFileurl(driverApp.getCyzgz5());
                fileInfo10.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo10);
                driverApp.setCyzgz5(fileInfo10.getFileid());
            }
            driverApp.setMima(driverApp.getMima());
            driverAMapper.save(driverApp);
            logger.info(driverApp.toString());
            //存到司机表中
            if(diverMapper.findBySfzh(driverApp.getSfzh())!=null){//重新注册
                DriverInfo driverInfo = diverMapper.findBySfzh(driverApp.getSfzh());
                driverInfo=DriverInfo.app(driverInfo,driverApp);
                diverMapper.saveAndFlush(driverInfo);
            }else {//第一次注册
                DriverInfo driverInfo = new DriverInfo(driverApp.getSjid(),driverApp.getXingming(),driverApp.getSfzh(),driverApp.getSjhm(),"","");
                diverMapper.save(driverInfo);
                DriverInfo driverInfo1 = diverMapper.findBySjid(driverApp.getSjid());
                driverInfo1=DriverInfo.app(driverInfo1,driverApp);
                diverMapper.saveAndFlush(driverInfo1);
            }
            //存到用户表中
            if(userMapper.findByYhm(driverApp.getSfzh())!=null){//重新注册
                UserInfo userInfo = userMapper.findByYhm(driverApp.getSfzh());
                String mima = GlobalParam.getMD5(driverApp.getMima());
                userInfo.setMima(mima);
                userInfo.setShzt("未审核");
                userInfo.setSjh(driverApp.getSjhm());
                userInfo.setZsxm(driverApp.getXingming());
                userInfo.setBumenid("");
                userInfo.setZcsj(driverApp.getLasttime());
                userInfo.setSfcz(true);
                userInfo.setLasttime(driverApp.getLasttime());
                userInfo.setYuanyin("");
                userMapper.saveAndFlush(userInfo);
                DriverInfo driverInfo1 = diverMapper.findBySfzh(driverApp.getSfzh());
                driverInfo1.setYhid(userInfo.getYhid());
                diverMapper.saveAndFlush(driverInfo1);
            }else {//第一次注册
                UserInfo userInfo = new UserInfo(driverApp);
                userMapper.save(userInfo);
                DriverInfo driverInfo1 = diverMapper.findBySfzh(driverApp.getSfzh());
                driverInfo1.setYhid(userInfo.getYhid());
                diverMapper.saveAndFlush(driverInfo1);
            }

        }
        return list;
    }

    //司机编辑个人中心
    @MonitorRequest
    @RequestMapping(value = "driverappmine", method = RequestMethod.PUT)
    public List<Map<String,Object>> updateMine(@RequestBody DriverApp driverApp) throws NoSuchAlgorithmException {
        List<Map<String,Object>>  list = new ArrayList<>();
        Map<String,Object>  map = new HashMap<>();
        if(driverApp.getJsznjrq().equals("")||!checkRiqi(driverApp.getJsznjrq())){
            map.put("jsznjrq", "0");
        }
        if(driverApp.getCyzgznjrq().equals("")||!checkRiqi(driverApp.getCyzgznjrq())){
            map.put("cyzgznjrq", "0");
        }
        DriverApp olddriverapp = driverAMapper.findBySjidAndSfcz(driverApp.getSjid(),true);
        if(driverApp.getSjhm().equals("")||!checkSjh(driverApp.getSjhm())){
            map.put("sjhm", "0");
        }else if (driverAMapper.findBySjhmandShzt(driverApp.getSjhm(),"未审核")!=null||(!driverApp.getSjhm().equals(olddriverapp.getSjhm())&&driverAMapper.findBySjhmandShzt(driverApp.getSjhm(),"审核通过")!=null)){
            map.put("sjhm", "2");
        }
        list.add(map);
        if(map.isEmpty()){
            List<DriverApp>driverApps = driverAMapper.findBySjidandsfcz(driverApp.getSjid());
            DriverApp driverApp1 = driverApps.get(0);
            String jsznjrq = driverApp.getJsznjrq();
            String jsznjrq1 = jsznjrq.substring(0,10);
            driverApp1.setJsznjrq(jsznjrq1);
            String cyzgznjrq = driverApp.getCyzgznjrq();
            String cyzgznjrq1 = cyzgznjrq.substring(0,10);
            driverApp1.setCyzgznjrq(cyzgznjrq1);
            driverApp1.setLasttime(GlobalParam.getTime());
            driverApp1.setXinxi("");
            driverApp1.setSfcg(false);
            driverApp1.setSfgrzx(true);
            driverApp1.setShzt("未审核");
            driverApp1.setSjhm(driverApp.getSjhm());
            if(driverApp.getSfzzm()!=null&&!driverApp.getSfzzm().equals("")){
                FileInfo fileInfo1 = fileMapper.findByFileurl(driverApp.getSfzzm());
                fileInfo1.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo1);
                driverApp1.setSfzzm(fileInfo1.getFileid());
            }
            if(driverApp.getSfzfm()!=null&&!driverApp.getSfzfm().equals("")){
                FileInfo fileInfo2 = fileMapper.findByFileurl(driverApp.getSfzfm());
                fileInfo2.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo2);
                driverApp1.setSfzfm(fileInfo2.getFileid());
            }
            if(driverApp.getSjsfzsbsz()!=null&&!driverApp.getSjsfzsbsz().equals("")){
                FileInfo fileInfo3 = fileMapper.findByFileurl(driverApp.getSjsfzsbsz());
                fileInfo3.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo3);
                driverApp1.setSjsfzsbsz(fileInfo3.getFileid());
            }
            if(driverApp.getJszzb()!=null&&!driverApp.getJszzb().equals("")){
                FileInfo fileInfo4 = fileMapper.findByFileurl(driverApp.getJszzb());
                fileInfo4.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo4);
                driverApp1.setJszzb(fileInfo4.getFileid());
            }
            if(driverApp.getJszfb()!=null&&!driverApp.getJszfb().equals("")){
                FileInfo fileInfo5 = fileMapper.findByFileurl(driverApp.getJszfb());
                fileInfo5.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo5);
                driverApp1.setJszfb(fileInfo5.getFileid());
            }
            if(driverApp.getCyzgz1()!=null&&!driverApp.getCyzgz1().equals("")) {
                FileInfo fileInfo6 = fileMapper.findByFileurl(driverApp.getCyzgz1());
                fileInfo6.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo6);
                driverApp1.setCyzgz2(fileInfo6.getFileid());
            }
            DriverApp driverApp2 = driverAMapper.findBySjidAndSfcz(driverApp.getSjid(),true);
            if(driverApp.getCyzgz2()!=null&&!driverApp.getCyzgz2().equals("")&&!driverApp.getCyzgz2().equals("1")) {
                FileInfo fileInfo7 = fileMapper.findByFileurl(driverApp.getCyzgz2());
                fileInfo7.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo7);
                driverApp1.setCyzgz2(fileInfo7.getFileid());
            }else if(driverApp.getCyzgz2().equals("")){
                driverApp1.setCyzgz2(driverApp2.getCyzgz2());
            }else if(driverApp.getCyzgz2().equals("1")){
                driverApp1.setCyzgz2("");
            }
            if(driverApp.getCyzgz3()!=null&&!driverApp.getCyzgz3().equals("")&&!driverApp.getCyzgz3().equals("1")) {
                FileInfo fileInfo8 = fileMapper.findByFileurl(driverApp.getCyzgz3());
                fileInfo8.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo8);
                driverApp1.setCyzgz3(fileInfo8.getFileid());
            }else if(driverApp.getCyzgz3().equals("")){
                driverApp1.setCyzgz3(driverApp2.getCyzgz3());
            }else if(driverApp.getCyzgz3().equals("1")){
                driverApp1.setCyzgz3("");
            }
            if(driverApp.getCyzgz4()!=null&&!driverApp.getCyzgz4().equals("")&&!driverApp.getCyzgz4().equals("1")) {
                FileInfo fileInfo9 = fileMapper.findByFileurl(driverApp.getCyzgz4());
                fileInfo9.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo9);
                driverApp1.setCyzgz4(fileInfo9.getFileid());
            }else if(driverApp.getCyzgz4().equals("")){
                driverApp1.setCyzgz4(driverApp2.getCyzgz4());
            }else if(driverApp.getCyzgz4().equals("1")){
                driverApp1.setCyzgz4("");
            }
            if(driverApp.getCyzgz5()!=null&&!driverApp.getCyzgz5().equals("")&&!driverApp.getCyzgz5().equals("1")) {
                FileInfo fileInfo10 = fileMapper.findByFileurl(driverApp.getCyzgz5());
                fileInfo10.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo10);
                driverApp1.setCyzgz5(fileInfo10.getFileid());
            }else if(driverApp.getCyzgz5().equals("")){
                driverApp1.setCyzgz5(driverApp2.getCyzgz5());
            }else if(driverApp.getCyzgz5().equals("1")){
                driverApp1.setCyzgz5("");
            }
            driverAMapper.saveAndFlush(driverApp1);
            logger.info(driverApp.toString());
        }
        return list;
    }

    //司机注册列表
    @RequestMapping(value = "driverapp/list", method = RequestMethod.POST)
    public ReturnInfo findDriverApp(){
        return ReturnInfo.info2(driverAMapper.findAll());
    }

    //管理员认证司机信息
    @MonitorRequest
    @RequestMapping(value = "driverapp", method = RequestMethod.PUT)
    public List<Map<String,Object>> updateDriverApp(@RequestBody DriverApp driverApp){
        List<Map<String,Object>>  list = new ArrayList<>();
        Map<String,Object>  map = new HashMap<>();

        List<DriverApp>driverApps = driverAMapper.findBySjidandsfcz(driverApp.getSjid());
        DriverApp driverApp1 = driverApps.get(0);
        if(driverApp.getSjid()==null||driverApp.getSjid().equals("")){
            map.put("sjid", "0");
        }else if(driverAMapper.findOne(driverApp.getSjid())==null){
            map.put("sjid", "1");
        }
        if(driverApp.getShzt()==null||(!driverApp.getShzt().equals("审核通过")&&!driverApp.getShzt().equals("审核不通过"))){
            map.put("shzt", "0");
        }
        if(!driverApp1.getShzt().equals("未审核")){
            map.put("shzt", "2");
        }
        if(driverApp.getShzt()!=null&&driverApp.getShzt().equals("审核不通过")&&(driverApp.getYuanyin()==null||driverApp.getYuanyin().equals(""))){
            map.put("yuanyin", "0");
        }
//        if(driverApp.getXinxi()==null){
//            map.put("xinxi", "0");
//        }
        list.add(map);
        if(map.isEmpty()){
            UserInfo userInfo = userMapper.findByYhm(driverApp.getSfzh());
            if (driverApp.getShzt().equals("审核不通过")){
                driverApp.setSfcg(false);
                DriverApp driverApp2 = driverAMapper.findBySjidAndSfcz(driverApp.getSjid(),true);
                if(driverApp2.getSfgrzx()==false){
                    userInfo.setShzt("审核不通过");
                    userInfo.setYuanyin(driverApp.getYuanyin());
                }else {
                    userInfo.setShzt("审核通过");
                    userInfo.setYuanyin(driverApp.getYuanyin());
                }
//                if(diverMapper.findBySjid(driverApp.getSjid())!=null){
//                    DriverInfo driverInfo = diverMapper.findBySjid(driverApp.getSjid());
//                    driverInfo.setSfcz(false);
//                    diverMapper.saveAndFlush(driverInfo);
//                }
            }else if (driverApp.getShzt().equals("审核通过")&& diverMapper.findBySjid(driverApp.getSjid())==null){
                DriverInfo driverInfo = diverMapper.findBySjidnotTrue(driverApp.getSjid());
                driverInfo.setSfcz(true);
                diverMapper.saveAndFlush(driverInfo);
                driverApp.setSfcg(true);
                driverApp.setYuanyin("");
                userInfo.setShzt("审核通过");
                userInfo.setYuanyin("");
                FileInfo fileInfo1 = fileMapper.findByFileid(driverApp.getSfzzm());
                fileInfo1.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo1);
                FileInfo fileInfo2 = fileMapper.findByFileid(driverApp.getSfzfm());
                fileInfo2.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo2);
                FileInfo fileInfo3 = fileMapper.findByFileid(driverApp.getSjsfzsbsz());
                fileInfo3.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo3);
                FileInfo fileInfo4 = fileMapper.findByFileid(driverApp.getJszzb());
                fileInfo4.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo4);
                FileInfo fileInfo5 = fileMapper.findByFileid(driverApp.getJszfb());
                fileInfo5.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo5);
                FileInfo fileInfo6 = fileMapper.findByFileid(driverApp.getCyzgz1());
                fileInfo6.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo6);
                if(driverApp.getCyzgz2()!=null&&!driverApp.getCyzgz2().equals("")) {
                    FileInfo fileInfo7 = fileMapper.findByFileid(driverApp.getCyzgz2());
                    fileInfo7.setSfcz(true);
                    fileMapper.saveAndFlush(fileInfo7);
                }
                if(driverApp.getCyzgz3()!=null&&!driverApp.getCyzgz3().equals("")) {
                    FileInfo fileInfo8 = fileMapper.findByFileid(driverApp.getCyzgz3());
                    fileInfo8.setSfcz(true);
                    fileMapper.saveAndFlush(fileInfo8);
                }
                if(driverApp.getCyzgz4()!=null&&!driverApp.getCyzgz4().equals("")) {
                    FileInfo fileInfo9 = fileMapper.findByFileid(driverApp.getCyzgz4());
                    fileInfo9.setSfcz(true);
                    fileMapper.saveAndFlush(fileInfo9);
                }
                if(driverApp.getCyzgz5()!=null&&!driverApp.getCyzgz5().equals("")) {
                    FileInfo fileInfo10 = fileMapper.findByFileid(driverApp.getCyzgz5());
                    fileInfo10.setSfcz(true);
                    fileMapper.saveAndFlush(fileInfo10);
                }
            }else if(driverApp.getShzt().equals("审核通过")&& diverMapper.findBySjid(driverApp.getSjid())!=null){
                DriverInfo driverInfo = diverMapper.findBySjid(driverApp.getSjid());
                driverInfo.setJsysj(driverApp.getSjhm());
                driverInfo.setCyzgznjrq(driverApp.getCyzgznjrq());
                driverInfo.setJsznjrq(driverApp.getJsznjrq());
                driverInfo.setSfzfyj(driverApp.getSfzzm());
                driverInfo.setSfzfm(driverApp.getSfzfm());
                driverInfo.setSjsfzsbsz(driverApp.getSjsfzsbsz());
                driverInfo.setJszfyj(driverApp.getJszzb());
                driverInfo.setJszfb(driverApp.getJszfb());
                driverInfo.setCyzgz1(driverApp.getCyzgz1());
                if(driverApp.getCyzgz2()!=null&&!driverApp.getCyzgz2().equals("")){
                    driverInfo.setCyzgz2(driverApp.getCyzgz2());
                }else if(driverApp.getCyzgz2()!=null&&driverApp.getCyzgz2().equals("")){
                    driverInfo.setCyzgz2("");
                }
                if(driverApp.getCyzgz3()!=null&&!driverApp.getCyzgz3().equals("")){
                    driverInfo.setCyzgz3(driverApp.getCyzgz3());
                }else if(driverApp.getCyzgz3()!=null&&driverApp.getCyzgz3().equals("")){
                    driverInfo.setCyzgz3("");
                }
                if(driverApp.getCyzgz4()!=null&&!driverApp.getCyzgz4().equals("")){
                    driverInfo.setCyzgz4(driverApp.getCyzgz4());
                }else if(driverApp.getCyzgz4()!=null&&driverApp.getCyzgz4().equals("")){
                    driverInfo.setCyzgz4("");
                }
                if(driverApp.getCyzgz5()!=null&&!driverApp.getCyzgz5().equals("")){
                    driverInfo.setCyzgz5(driverApp.getCyzgz5());
                }else if(driverApp.getCyzgz5()!=null&&driverApp.getCyzgz5().equals("")){
                    driverInfo.setCyzgz5("");
                }
                diverMapper.saveAndFlush(driverInfo);
                FileInfo fileInfo1 = fileMapper.findByFileid(driverApp.getSfzzm());
                fileInfo1.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo1);
                FileInfo fileInfo2 = fileMapper.findByFileid(driverApp.getSfzfm());
                fileInfo2.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo2);
                FileInfo fileInfo3 = fileMapper.findByFileid(driverApp.getSjsfzsbsz());
                fileInfo3.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo3);
                FileInfo fileInfo4 = fileMapper.findByFileid(driverApp.getJszzb());
                fileInfo4.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo4);
                FileInfo fileInfo5 = fileMapper.findByFileid(driverApp.getJszfb());
                fileInfo5.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo5);
                FileInfo fileInfo6 = fileMapper.findByFileid(driverApp.getCyzgz1());
                fileInfo6.setSfcz(true);
                fileMapper.saveAndFlush(fileInfo6);
                if(driverApp.getCyzgz2()!=null&&!driverApp.getCyzgz2().equals("")) {
                    FileInfo fileInfo7 = fileMapper.findByFileid(driverApp.getCyzgz2());
                    fileInfo7.setSfcz(true);
                    fileMapper.saveAndFlush(fileInfo7);
                }
                if(driverApp.getCyzgz3()!=null&&!driverApp.getCyzgz3().equals("")) {
                    FileInfo fileInfo8 = fileMapper.findByFileid(driverApp.getCyzgz3());
                    fileInfo8.setSfcz(true);
                    fileMapper.saveAndFlush(fileInfo8);
                }
                if(driverApp.getCyzgz4()!=null&&!driverApp.getCyzgz4().equals("")) {
                    FileInfo fileInfo9 = fileMapper.findByFileid(driverApp.getCyzgz4());
                    fileInfo9.setSfcz(true);
                    fileMapper.saveAndFlush(fileInfo9);
                }
                if(driverApp.getCyzgz5()!=null&&!driverApp.getCyzgz5().equals("")) {
                    FileInfo fileInfo10 = fileMapper.findByFileid(driverApp.getCyzgz5());
                    fileInfo10.setSfcz(true);
                    fileMapper.saveAndFlush(fileInfo10);
                }
                userInfo.setShzt("审核通过");
                userInfo.setYuanyin("");
                userInfo.setSjh(driverApp.getSjhm());
                driverApp.setSfcg(true);
                driverApp.setYuanyin("");

            }
            userMapper.saveAndFlush(userInfo);
            driverAMapper.updateBySjidSh(driverApp.getYuanyin(), driverApp.getSfcg(), driverApp.getShzt(),driverApp.getSjid());
            logger.info(driverApp.toString());
        }
        return list;
    }

    //检查身份证号格式
    private Boolean checkSfzh(String sfzh) {
        Boolean b = false;
        if(sfzh.matches("^(\\d{15}$|^\\d{18}$|^\\d{17}(\\d|X|x))$")){
            b = true;
        }
        return b;
    }

    //检查姓名格式
    private Boolean checkXm(String jsyxm){
        Boolean b = false;
        if(jsyxm.matches("^[\\u4E00-\\u9FA5A-Za-z]+$")){
            b = true;
        }
        return b;
    }

    //检查日期格式
    private Boolean checkRiqi(String riqi){
        Boolean b = false;

            b = true;

        return b;
    }

    //检查密码格式
    private Boolean checkPsw(String mima){
        Boolean b = false;
        if(mima.matches("^[0-9]{6,12}$")){
            b = true;
        }
        return b;
    }

    //检查手机号码格式
    private Boolean checkSjh(String sjh){
        Boolean b = false;
        if(sjh.matches("^1[0-9 ]{10,12}$")){
            b = true;
        }
        return b;
    }

}
